package com.sy.third;

import redis.clients.jedis.Jedis;

/**
 * @author maojq
 * @date 2020/11/25 0025 19:35
 */
public class JedisUtil {
    private Jedis jedis;
    private static JedisUtil util = new JedisUtil();

    private JedisUtil() {
        jedis = new Jedis("39.105.189.141", 6380);
    }

    public static JedisUtil getInstance() {
        return util;
    }

    //新增
    public void addStr(String key, String val) {
        jedis.set(key, val);
    }

    public void addStrEx(String key, String val, int seconds) {
        jedis.setex(key, seconds, val);
    }
    public void addHash(String key,String field,String value){
        jedis.hset(key, field, value);
    }
    public void addSet(String key, String... values) {
        jedis.sadd(key, values);
    }


    //删除
    public boolean delKeys(String... key) {
        return jedis.del(key) >0;
    }
    //修改
    //查询
    public String getStr(String key) {
        return jedis.get(key);
    }

    //系统
    public boolean ishave(String key) {
        return jedis.exists(key);
    }


    public void setTime(String key, int seconds) {
        jedis.expire(key, seconds);
    }
}
